/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package metricmaster.gui.projecttab;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import metricmaster.model.Activity;

/**
 *
 * @author markblanda
 */
public class NewActivityPanel extends JPanel implements ActionListener {
    private JTextField shopOrderField;
    private JTextField descriptionField;
    private JTextField startField;
    private JTextField finishField;
    private JButton addButton;
    private JButton clearButton;
    private GridBagConstraints c = new GridBagConstraints();
    
    public NewActivityPanel() {
        this.setLayout(new GridBagLayout());
        this.setBorder(new TitledBorder("New Activity"));
        setupComponents();
        clearButton.addActionListener(this);
    }
    
    private void setupComponents() {
        shopOrderField = new JTextField(15);
        descriptionField = new JTextField(15);
        startField = new JTextField(15);
        finishField = new JTextField(15);
        addButton = new JButton("Add");
        clearButton = new JButton("Clear");
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 0;
        this.add(new JLabel("Shop Order:"), c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 1;
        c.gridy = 0;
        this.add(shopOrderField, c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 2;
        c.gridy = 0;
        this.add(new JLabel("Start:"), c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 3;
        c.gridy = 0;
        this.add(startField, c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 4;
        c.gridy = 0;
        this.add(addButton, c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 1;
        this.add(new JLabel("Description"), c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 1;
        c.gridy = 1;
        this.add(descriptionField, c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 2;
        c.gridy = 1;
        this.add(new JLabel("Finish"), c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 3;
        c.gridy = 1;
        this.add(finishField, c);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 4;
        c.gridy = 1;
        this.add(clearButton, c);
    }

    /**
     * @return the addButton
     */
    public JButton getAddButton() {
        return addButton;
    }

    /**
     * @param addButton the addButton to set
     */
    public void setAddButton(JButton addButton) {
        this.addButton = addButton;
    }
    
    public Activity getNewActivity() {
        Activity act = new Activity();
        act.setDescription(descriptionField.getText());
        act.setShopOrder(shopOrderField.getText());
        act.setFinish(finishField.getText());
        act.setStart(startField.getText());
        return act;
    }
    
    public void clearFields() {
        shopOrderField.setText("");
        descriptionField.setText("");
        startField.setText("");
        finishField.setText("");
        
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        clearFields();
    }
}
